package com.yesallchina.wxapp.officialaccount.utils;

import java.math.BigDecimal;
import java.text.DecimalFormat;

public final class WxUtils {

    /***
     * 产生一个纯数字随机整数
     *
     * @param point 整数位数
     * @return
     */
    public static String getDigitRandom(int point) {
        String result = String.valueOf(Math.random());
        String f = "#####0";
        if (point > 0) {
            f = "";
            for (int i = 0; i < point - 1; i++) {
                f += "#";
            }
            f += "0";
        }
        BigDecimal rand = new BigDecimal(result);
        BigDecimal one = new BigDecimal(1);
        double d = rand.divide(one, point, BigDecimal.ROUND_HALF_UP).doubleValue();
        DecimalFormat df = new DecimalFormat(f);
        String t = df.format(d * Math.pow(10, point));
        if (t.length() < point) {
            int l = point - t.length();
            for (int i = 0; i < l; i++) {
                t += "0";
            }
        }
        return t;
    }

}
